﻿/// <reference path="/Scripts/qunit.js" />
/// <reference path="../Planets/js/loop.js" />
/// <reference path="/../Planets/js/loop.js" />
/// <reference path="/../Planets/js/planets.js" />
/// <reference path="../Planets/js/planets.js" />

module("Animation:");

test("planet first update", function () {

    var fakeCanvas = { width: 200, height: 200, getContext: function () { } };

    var anim = new Loop.Animation(fakeCanvas);

    var planet = new Planets.Planet(anim);
    planet.rotationCenter = [50, 50];
    planet.radius = 50;
    planet.speed = 1;
    planet.rotationRadius = 100;
    anim.animationElements.push(planet);

    anim.update(0);
    equal(planet.position[0], 150);
    equal(planet.position[1], 50);
    anim.update(1000);
    equal(planet.position[0], Math.cos(1) * 100 + 50);
    equal(planet.position[1], Math.sin(1) * 100 + 50);

    expect(4);
});

test("animation pause", function () {

    var fakeCanvas = { width: 200, height: 200, getContext: function () { } };
    window.requestAnimationFrame = function () {
    };

    var anim = new Loop.Animation(fakeCanvas);
    anim._enabled = true; //fake start

    var planet = new Planets.Planet(anim);
    planet.rotationCenter = [50, 50];
    planet.radius = 50;
    planet.speed = 1;
    planet.rotationRadius = 100;
    anim.animationElements.push(planet);

    anim.update(0);
    equal(planet.position[0], 150);
    equal(planet.position[1], 50);
    anim.update(1000);
    equal(planet.position[0], Math.cos(1) * 100 + 50);
    equal(planet.position[1], Math.sin(1) * 100 + 50);
    anim.pause();
    anim.update(2000);
    anim.update(3000);
    equal(planet.position[0], Math.cos(1) * 100 + 50);
    equal(planet.position[1], Math.sin(1) * 100 + 50);

    expect(6);

});

test("animation pause continue", function () {

    var fakeCanvas = { width: 200, height: 200, getContext: function () { } };
    window.requestAnimationFrame = function () {
    };

    var anim = new Loop.Animation(fakeCanvas);
    anim._enabled = true; //fake start

    var planet = new Planets.Planet(anim);
    planet.rotationCenter = [50, 50];
    planet.radius = 50;
    planet.speed = 1;
    planet.rotationRadius = 100;
    anim.animationElements.push(planet);

    anim.update(0);
    equal(planet.position[0], 150);
    equal(planet.position[1], 50);
    anim.update(1000);
    equal(planet.position[0], Math.cos(1) * 100 + 50);
    equal(planet.position[1], Math.sin(1) * 100 + 50);
    anim.pause();
    anim.update(2000);
    anim.update(3000);
    equal(planet.position[0], Math.cos(1) * 100 + 50);
    equal(planet.position[1], Math.sin(1) * 100 + 50);
        anim.continue();
    anim.update(4000);
    equal(planet.position[0], Math.cos(2) * 100 + 50);
    equal(planet.position[1], Math.sin(2) * 100 + 50);

    expect(8);

});
